import Vue from 'vue'
import Router from 'vue-router'

import store from '@/store/store.js';
import homePage from '@/components/homePage'
import writeBlog from '@/components/util/writeBlog'

import technologyCenter from "@/components/menu/technologyCenter"
import fileShop from "@/components/menu/fileShop"
import messageWall from "@/components/menu/messageWall"
import daily from "@/components/menu/daily"
import readArticle from "@/components/article/readArticle"
import shareSquare from "@/components/menu/shareSquare"
import allShare from "@/components/menu/homeMenu/allShare"

import tecShare from "@/components/menu/homeMenu/tecShare"
import category from "@/components/menu/homeMenu/category"

import searchWall from "@/components/menu/search/search"
import login from "@/components/menu/user/login"
import register from "@/components/menu/user/register"
import my from "@/components/menu/user/my"



Vue.use(Router)

let router =  new Router({
  linkActiveClass:'active',
  linkExactActiveClass:'eactive',
  routes: [
    {
      path: '/writeBlog',
      name: 'writeBlog',
      component: writeBlog,
    },
	
    {
      path: '/homePage',
      name: 'homePage',
      component: homePage,
      children:[
		  {
		  	  path:"category",
		  	  component:category,
		  	
		  	children:[
				{
				  path:"/",
				 redirect:'technologyCenter'
				},
		  		{
		  		  path:"fileShop",
		  		  component:fileShop,
		  		},
		  		
		  		{
		  		  path:"messageWall",
		  		  component:messageWall,
		  		},
		  		{
		  		  path:"daily",
		  		  component:daily,
		  		},
		  		{
		  		  path:"technologyCenter",
		  		  component:technologyCenter,
		  		},
		  	]
		  },
        {
          path:"login",
          component:login,
        },
        {
          path:"register",
          component:register,
        },
        {
          path:"my",
          component:my,
          meta: {
            requireAuth: true
           },
        },
		{
		  path:"searchWall",
		  component:searchWall,
		},		
        {
          path:"shareSquare",
          component:allShare,
        },
		
        

        // 博客欣赏
        {
          path:"readArticle",
          component:readArticle,
        },
        {
          path:"/",
          redirect:'shareSquare',
        },

      ],

    },
    {
      path:"/login",
      name:"login",
      component:login
    },
    {path:'/',
      redirect:'/homePage'
    }

  ]
})
//路由守卫
router.beforeEach((to,from,next)=>{
  if(to.matched.some(res=>res.meta.requireAuth)){
    console.log(Vue);
    //需要登录
    if(store.getters.getLogin){
      //登录了
      next();
    }else{
       next({
        path: '/homePage/register',
        query: {redirect: to.fullPath}
        })
    }
  }else{
    next()
  }
})
export default router;
